import axios from 'axios';
import store from "@/store";

const http = axios.create({
	baseURL: 'http://localhost:8888/api',
	timeout: 10000
})

// 请求拦截器
http.interceptors.request.use(config => {
	const token = store.getters.token
	if(token){
		config.headers['Authorization'] = token
	}
	return config;
}, err => {
	console.log('err' + err);
	return Promise.reject(err);
})

// 响应拦截器
http.interceptors.response.use(res => {
	return res.data
}, err => {
	console.log('err' + err);
	return Promise.reject(err);
})

export default http